package com.markhsiu.MiniMQ.producer;

import com.markhsiu.MiniMQ.model.Message;
import com.markhsiu.MiniMQ.model.Result;
import com.markhsiu.MiniMQ.model.constant.MessageSourceEnum;
import com.markhsiu.MiniMQ.remote.Client;
import com.markhsiu.MiniMQ.remote.transport.netty.NettyClient;

/**
 * Created by Mark Hsiu on 2017/2/8.
 */
public class Producer {
	
	private  Client client = new NettyClient();
	public Producer(){	
	}
	
	public Producer(Client client){
		this.client = client;
	}
	
	public void start(){
		 client.open();
	     client.connect();
	}
	
	public Result run(Message message){
		message.setSource(MessageSourceEnum.PRODUCER);;
        message.setTarget(MessageSourceEnum.BROKER);
        message.setTimestamp(System.nanoTime());
		return client.send(message);
	}
	
	public void end(){
		client.close();
	}

 
}
